/********************************************************************
*  sample.cu
*  This is a example of the CUDA program.
*********************************************************************/

#include <vector>
#include <iostream>
#include "../../include/GlobalMemory.hpp"

using namespace std;

extern void launchKernel(CH::GlobalMemory<float> & a_d);

/// std vector dump helper
template <class T>
void dump_vector(const std::vector<T>& cpu_vec)
{
	for(int i = 0; i < cpu_vec.size(); i++)
		std::cout << cpu_vec[i] << " ";
	std::cout << "\n";
}

/************************************************************************/
/* main                                                                 */
/************************************************************************/

int main(int argc, char* argv[])
{
	int N = 10;

	/// allocate arrays on host
	std::vector<float> a_h(N, 123);
	std::vector<float> b_h(N-2, 999);

	///a_h -> a_d
	CH::GlobalMemory<float> a_d(a_h);

	cout << "a_h\n";
	dump_vector(a_h);

	cout << "a_d\n";
	a_d.dump_to_screen();
	

	///b_h -> b_d
	CH::GlobalMemory<float> b_d;
	b_d.set_gpu_data(b_h);

	cout << "b_h\n";
	dump_vector(b_h);

	cout << "b_d\n";
	b_d.dump_to_screen();

	///a_d = b_d
	a_d = b_d;
	
	cout << "a_d after copy from b_d\n";
	a_d.dump_to_screen();

	launchKernel(a_d);

	///fetch data from a_d and dump
	cout << "a_d after kernel\n";

	std::vector<float> result;
	a_d.get_gpu_data(result);

	dump_vector(result);
	

	return 0;
}
